import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../page/main/splash_page.dart';
import '../../page/main/login_page.dart';
import '../../page/main/register_page.dart';
import '../../page/main/main_screen.dart';
import '../../page/home/home_page.dart';
import '../../page/discovered/discovered_page.dart';
import '../../page/release/release_page.dart';
import '../../page/profile/user_center_screen.dart';
import '../../page/profile/settings_screen.dart';
import '../../page/profile/user_info_edit_page.dart';
import '../../page/notification/message_center_page.dart';
import '../../page/chat/conversation_chat_page.dart';
import '../../page/encyclopedia/encyclopedia_list_page.dart';
import '../../page/encyclopedia/encyclopedia_detail_page.dart';
import '../../page/post/post_detail_page.dart';
import '../../page/video/video_player_page.dart';
import '../../page/activity/activity_detail_page.dart';
import '../../page/activity/upload_share_page.dart';
import '../../page/profile/other_user_center_screen.dart';
import '../../page/encyclopedia/favorite_encyclopedia_page.dart';
import '../../page/video/video_call_page.dart';

class AppRouteManager {
  static const String _launchRoute = '/app_launch';
  static const String _authRoute = '/user_auth';
  static const String _registerRoute = '/user_register';
  static const String _mainRoute = '/main_hub';
  static const String _homeRoute = '/home_base';
  static const String _discoveredRoute = '/explore_zone';
  static const String _releaseRoute = '/publish_center';
  static const String _userCenterRoute = '/user_profile_center';
  static const String _userConfigRoute = '/user_config_center';
  static const String _userInfoEditRoute = '/user_info_editor';
  static const String _messageCenterRoute = '/message_notification_center';
  static const String _conversationChatRoute = '/conversation_chat_view';
  static const String _encyclopediaListRoute = '/encyclopedia_list_view';
  static const String _encyclopediaDetailRoute = '/encyclopedia_detail_view';
  static const String _postDetailRoute = '/post_detail_view';
  static const String _videoPlayerRoute = '/video_player_view';
  static const String _activityDetailRoute = '/activity_detail_view';
  static const String _uploadShareRoute = '/upload_share_view';
  static const String _otherUserCenterRoute = '/other_user_center_view';
  static const String _favoriteEncyclopediaRoute =
      '/favorite_encyclopedia_view';
  static const String _videoCallRoute = '/video_call_view';

  static List<GetPage> getAppRoutes() {
    return [
      // 启动页面路由
      GetPage(
        name: _launchRoute,
        page: () => const AppLaunchScreen(),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 登录页面路由
      GetPage(
        name: _authRoute,
        page: () => const UserAuthScreen(),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 注册页面路由
      GetPage(
        name: _registerRoute,
        page: () => const UserRegistrationScreen(),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 主页面路由
      GetPage(
        name: _mainRoute,
        page: () => const MainScreen(),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 首页路由
      GetPage(
        name: _homeRoute,
        page: () => const HomePage(),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 发现页路由
      GetPage(
        name: _discoveredRoute,
        page: () => const DiscoveredPage(),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 发布页路由
      GetPage(
        name: _releaseRoute,
        page: () => const ReleasePage(),
        curve: Curves.easeInOut,
        transition: Transition.downToUp,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 用户中心路由
      GetPage(
        name: _userCenterRoute,
        page: () => const UserCenterScreen(),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 用户配置中心路由
      GetPage(
        name: _userConfigRoute,
        page: () => const UserConfigCenter(),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 用户信息编辑路由
      GetPage(
        name: _userInfoEditRoute,
        page: () => const UserProfileEditor(),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 消息中心路由
      GetPage(
        name: _messageCenterRoute,
        page: () => const MessageCenterPage(),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 对话聊天路由
      GetPage(
        name: _conversationChatRoute,
        page:
            () => ConversationChatPage(
              chatType: Get.arguments['chatType'] ?? 'private',
              chatId: Get.arguments['chatId'] ?? '',
              chatTitle: Get.arguments['chatTitle'],
            ),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 百科列表路由
      GetPage(
        name: _encyclopediaListRoute,
        page:
            () => EncyclopediaListPage(
              category: Get.arguments['category'] ?? 'animal',
            ),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 百科详情路由
      GetPage(
        name: _encyclopediaDetailRoute,
        page:
            () => EncyclopediaDetailPage(
              encyclopediaId: Get.arguments['encyclopediaId'] ?? '',
            ),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 动态详情路由
      GetPage(
        name: _postDetailRoute,
        page: () => PostDetailPage(postId: Get.arguments['postId'] ?? ''),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 视频播放路由
      GetPage(
        name: _videoPlayerRoute,
        page:
            () => VideoPlayerPage(
              videoUrl: Get.arguments['videoUrl'] ?? '',
              videoType: Get.arguments['videoType'],
            ),
        curve: Curves.easeInOut,
        transition: Transition.fadeIn,
        transitionDuration: const Duration(milliseconds: 300),
      ),

      // 活动详情路由
      GetPage(
        name: _activityDetailRoute,
        page:
            () => ActivityDetailPage(
              activityId: Get.arguments['activityId'] ?? '',
            ),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 上传分享图片路由
      GetPage(
        name: _uploadShareRoute,
        page:
            () => UploadSharePage(
              defaultActivityId: Get.arguments?['defaultActivityId'],
            ),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 其他用户主页路由
      GetPage(
        name: _otherUserCenterRoute,
        page:
            () => OtherUserCenterScreen(
              targetUserId: Get.arguments['targetUserId'] ?? '',
            ),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 收藏百科路由
      GetPage(
        name: _favoriteEncyclopediaRoute,
        page: () => const FavoriteEncyclopediaPage(),
        curve: Curves.easeInOut,
        transition: Transition.rightToLeftWithFade,
        transitionDuration: const Duration(milliseconds: 400),
      ),

      // 视频通话路由
      GetPage(
        name: _videoCallRoute,
        page:
            () => VideoCallPage(
              targetUserId: Get.arguments['targetUserId'] ?? '',
            ),
        curve: Curves.easeInOut,
        transition: Transition.fadeIn,
        transitionDuration: const Duration(milliseconds: 300),
      ),
    ];
  }

  /// 导航到启动页面
  static void navigateToLaunch() {
    Get.offAllNamed(_launchRoute);
  }

  /// 导航到登录页面
  static void navigateToAuth() {
    Get.toNamed(_authRoute);
  }

  /// 导航到注册页面
  static void navigateToRegister() {
    Get.toNamed(_registerRoute);
  }

  /// 导航到主页面
  static void navigateToMain() {
    Get.offAllNamed(_mainRoute);
  }

  /// 导航到首页
  static void navigateToHome() {
    Get.toNamed(_homeRoute);
  }

  /// 导航到发现页
  static void navigateToDiscovered() {
    Get.toNamed(_discoveredRoute);
  }

  /// 导航到发布页
  static void navigateToRelease() {
    Get.toNamed(_releaseRoute);
  }

  /// 导航到用户中心
  static void navigateToUserCenter() {
    Get.toNamed(_userCenterRoute);
  }

  /// 导航到用户配置中心
  static void navigateToUserConfig() {
    Get.toNamed(_userConfigRoute);
  }

  /// 导航到用户信息编辑
  static void navigateToUserInfoEdit() {
    Get.toNamed(_userInfoEditRoute);
  }

  /// 导航到消息通知
  static void navigateToMessageCenter() {
    Get.toNamed(_messageCenterRoute);
  }

  /// 导航到对话聊天
  static void navigateToConversationChat({
    required String chatType,
    required String chatId,
    String? chatTitle,
  }) {
    Get.toNamed(
      _conversationChatRoute,
      arguments: {
        'chatType': chatType,
        'chatId': chatId,
        'chatTitle': chatTitle,
      },
    );
  }

  /// 导航到百科列表
  static void navigateToEncyclopediaList(String category) {
    Get.toNamed(_encyclopediaListRoute, arguments: {'category': category});
  }

  /// 导航到百科详情
  static void navigateToEncyclopediaDetail(String encyclopediaId) {
    Get.toNamed(
      _encyclopediaDetailRoute,
      arguments: {'encyclopediaId': encyclopediaId},
    );
  }

  /// 导航到动态详情页
  static void navigateToPostDetail(String postId) {
    Get.toNamed(_postDetailRoute, arguments: {'postId': postId});
  }

  /// 导航到视频播放页
  static void navigateToVideoPlayer(
    String videoUrl, {
    VideoResourceType? videoType,
  }) {
    Get.toNamed(
      _videoPlayerRoute,
      arguments: {'videoUrl': videoUrl, 'videoType': videoType},
    );
  }

  /// 导航到活动详情页
  static void navigateToActivityDetail(String activityId) {
    Get.toNamed(_activityDetailRoute, arguments: {'activityId': activityId});
  }

  /// 导航到上传分享图片页
  static void navigateToUploadShare({String? defaultActivityId}) {
    Get.toNamed(
      _uploadShareRoute,
      arguments: {'defaultActivityId': defaultActivityId},
    );
  }

  /// 导航到其他用户主页
  static void navigateToOtherUserCenter(String targetUserId) {
    Get.toNamed(
      _otherUserCenterRoute,
      arguments: {'targetUserId': targetUserId},
    );
  }

  /// 导航到收藏百科页面
  static void navigateToFavoriteEncyclopedia() {
    Get.toNamed(_favoriteEncyclopediaRoute);
  }

  /// 导航到视频通话页面
  static void navigateToVideoCall(String targetUserId) {
    Get.toNamed(_videoCallRoute, arguments: {'targetUserId': targetUserId});
  }

  /// 返回上一页
  static void goBack() {
    Get.back();
  }

  /// 检查当前路由
  static String getCurrentRoute() {
    return Get.currentRoute;
  }

  /// 检查是否在指定路由
  static bool isCurrentRoute(String routeName) {
    return Get.currentRoute == routeName;
  }
}
